package com.graduation.community_manager.controller;

import java.util.Arrays;
import java.util.List;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.pagehelper.PageInfo;
import com.graduation.community_manager.entity.CmUserEntity;
import com.graduation.community_manager.service.CmUserService;
import com.graduation.community_manager.vo.PageCmUserVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户表
 *
 * @author wdh
 */
@RestController
@CrossOrigin
@RequestMapping("/cmUser")
public class CmUserController {

    @Autowired
    private CmUserService cmUserService;

    /**
     * 列表
     */
    @ApiOperation(value = "获得用户分页")
    @PostMapping("/page")
    public PageInfo<CmUserEntity> cmUserPage(@RequestBody PageCmUserVO pageCmUserVO){
        return cmUserService.cmUserPage(pageCmUserVO);
    }

    /**
     * 信息
     */
    @ApiOperation(value = "获得用户信息")
    @GetMapping("/info")
    public CmUserEntity info(@RequestParam("id") Long id){
		CmUserEntity cmUser = cmUserService.getById(id);
        return cmUser;
    }

    /**
     * 保存
     */
    @ApiOperation(value = "创建用户")
    @PostMapping("/save")
    public Boolean save(@RequestBody CmUserEntity cmUser){
		cmUserService.save(cmUser);
        return true;
    }

    /**
     * 修改
     */
    @ApiOperation(value = "更新用户信息")
    @PutMapping("/update")
    public Boolean update(@RequestBody CmUserEntity cmUser) {
        cmUserService.updateById(cmUser);
        return true;
    }
    /**
     * 删除
     */
    @ApiOperation(value = "删除用户信息")
    @DeleteMapping("/delete")
    public Boolean delete(@RequestBody Long[] ids){
		cmUserService.removeByIds(Arrays.asList(ids));
        return true;
    }

}
